<template>
  <div class="app-container">
    <el-input
      v-model="filterText"
      placeholder="查询条件"
      style="margin-bottom: 25px;width: 80%"
    />

    <el-tree
      ref="subjectTree"
      :data="subjectList"
      :props="defaultProps"
      :filter-node-method="filterNode"
      style="margin-top: 10px"
    />
  </div>
</template>

<script>
import subjectApi from "@/api/subject";
export default {
  name: "list.vue",
  data() {
    return {
      filterText: '', // 过滤文本
      subjectList: [], // 数据列表
      defaultProps: {// 属性列表数据属性的key
        children: 'children',
        label: 'title'
      }
    }
  },
  watch: {
    filterText(newVal,oldVal) {
      /*console.log('oldVal',oldVal)
      console.log('newVal',newVal)*/
      this.$refs.subjectTree.filter(newVal)
    }
  },

  created() {
    this.getNodeList()
  },

  methods: {
    getNodeList() {
      subjectApi.getNestedTreeList().then(res => {
        this.subjectList = res.data.items;
      })
    },


    // 过滤节点
    filterNode(value, data) {
      console.log("value",value)
      if (!value) return true
      return data.title.toLowerCase().indexOf(value) !== -1
    }
  }
}
</script>

<style scoped>

</style>
